package org.kernely.test.todopage;

import org.kernely.ui.mvp.IKernelyView;

import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

/**
 * ToDoView Class
 */
public class ToDoView extends GridLayout implements IKernelyView{
	/**
	 * The Serial Version ID
	 */
	private static final long serialVersionUID = -6349085013593150572L;

	/**
	 * The View ID
	 */
	public static final Class<? extends IKernelyView> ID_VIEW = ToDoView.class;

	private Panel northPanel = new Panel();
	private Panel southPanel = new Panel();
	private Panel eastPanel = new Panel();
	private Table table;
	private TextField taskTextField;
	private ComboBox users;
	private Button validateButton;
	private Button dropButton;
	private Button refreshButton;
	private VerticalLayout westLayout;

	/**
	 * ToDoView's Constructor
	 */
	public ToDoView(){
		taskTextField = new TextField("New task");
		validateButton = new Button("Save task");
		refreshButton = new Button("Refresh table");
		validateButton.setClickShortcut(KeyCode.ENTER);
		users = new ComboBox();
		table = new Table();

		dropButton = new Button("Drop all tasks");

		westLayout = new VerticalLayout();
		
		this.setColumns(4);
		this.setRows(1);
		westLayout.addComponent(northPanel);
		westLayout.addComponent(southPanel);

		this.addComponent(westLayout);
		this.addComponent(eastPanel,1,0,3,0);

		this.setSizeFull();
		
		table.setSizeFull();
		table.setPageLength(0);
		table.setHeight(100, Sizeable.UNITS_PERCENTAGE);
		table.addContainerProperty("Id", String.class, null);
		table.addContainerProperty("Task", String.class,  null);
		table.addContainerProperty("Owner", String.class,  null);
		
		northPanel.addComponent(taskTextField);
		northPanel.addComponent(users);
		northPanel.addComponent(validateButton);
		

		eastPanel.addComponent(refreshButton);
		eastPanel.addComponent(dropButton);
		eastPanel.addComponent(table);
		
		southPanel.addComponent(new Label("Step 1 : You can add a new ToDo task with the form located above. Just enter a text and click on 'Save task'."));
		southPanel.addComponent(new Label("Step 2 : When you save your task, the table is update and your new task is displayed and associated to the current user, by default."));		
		southPanel.addComponent(new Label("Step 3 : Try to add a task to another user. If you are admininistrator, you see the task, if not you can't see the task. This is because you don't have permission to see other user's task."));
		southPanel.addComponent(new Label("Step 4 : You can refresh the table with the button \"Refresh table\"."));
	}
	
	/**
	 * @see org.kernely.core.service.IKernelyView#getComponent()
	 */
	@Override
	public final Component getComponent() {
		return this;
	}

	/**
	 * Gets the table
	 * @return the table
	 */
	public final Table getTable() {
		return table;
	}

	/**
	 * Gets the taskTextField
	 * @return the taskTextField
	 */
	public final TextField getTaskTextField() {
		return taskTextField;
	}

	/**
	 * Gets the comboBox which contains users
	 * @return the users
	 */
	public final ComboBox getUsers() {
		return users;
	}

	/**
	 * Gets the validateButton
	 * @return the validateButton
	 */
	public final Button getValidateButton() {
		return validateButton;
	}

	/**
	 * Gets the dropButton
	 * @return the dropButton
	 */
	public final Button getDropButton() {
		return dropButton;
	}

	/**
	 * Gets the refreshButton
	 * @return the refreshButton
	 */
	public final Button getRefreshButton() {
		return refreshButton;
	}	

	
	
}
